﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyCommon.Helper
{
    public class FileHelper : IDisposable
    {
        private bool _alreadyDispose = false;
        public FileHelper()
        {
            
        }

        ~FileHelper() { 
            Dispose();
        }
        protected virtual void Dispose(bool isDisposing) {
            if (_alreadyDispose) return;
            _alreadyDispose = true;
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        ///  读文件
        /// </summary>
        /// <param name="path"></param>
        /// <param name="encoding"></param>
        /// <returns></returns>
        public static string ReadFile(string path,Encoding encoding)
        {
            string s = "";
            if (!File.Exists(path)) s = "目录不存在";
            else
            {
                StreamReader streamReader = new StreamReader(path,encoding);
                s = streamReader.ReadToEnd();
                streamReader.Close();
                streamReader.Dispose();
            }
            return s;
        }
    }
}
